package com.baiyang.app.ui.bookCity;

import android.content.Context;

import com.alibaba.fastjson.JSONObject;
import com.baiyang.app.tool.DataTool;
import com.baiyang.app.tool.LogUtils;
import com.baiyang.app.tool.net.SendMsgUtil;
import com.baiyang.app.tool.net.Urls;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Response;

public class BookCityService {

    private Context context;
    private BookCityViewModel viewModel;

    public BookCityService(Context context,BookCityViewModel viewModel){
        this.context = context;
        this.viewModel = viewModel;
    }

    public void getData(){
        new SendMsgUtil(){
            @Override
            public void deal(Call call, Response response) throws IOException {
                if(response.code() == 200){
                    String str = response.body().string();
                    LogUtils.i("article",str);
                    viewModel.setGetDataResult(JSONObject.parseObject(str));
                }else{
                    LogUtils.i("article","code:" + response.code());
                }
            }

            @Override
            public void dealFailure(Call call, IOException e) throws IOException {
                LogUtils.i("register","IOException:" + e.getLocalizedMessage());
            }
        }.sendPost(Urls.Article.GET_DATA,null);
    }
}
